﻿using QuanLyKho.DTO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace QuanLyKho.DAL
{
    class HangHoaDAO : DataProvider
    {
        public ArrayList GetListHang()
        {
            string sqlString = "Select * from HangHoa";
            adapter = new OleDbDataAdapter(sqlString, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            ArrayList listHangHoa = ConvertDataSetToArrayList(dataSet);

            return listHangHoa;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            HangHoaDTO hangHoaDTO = new HangHoaDTO();
            hangHoaDTO.MaHang = dt.Rows[i]["MaHang"].ToString();
            hangHoaDTO.TenHang = dt.Rows[i]["TenHang"].ToString();

            return (object) hangHoaDTO;
        }

        public void insert(HangHoaDTO hangHoaDTO)
        {
            string sqlString = "insert into HangHoa values('"
                + hangHoaDTO.MaHang + "','"
                + hangHoaDTO.TenHang + "','"
                + 0 + "')";
            ExecuteNonQuery(sqlString);
        }
    }
}
